package com.goodving.guli.server;


import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.view.C3657a;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.ResponseHandlerInterface;
import com.loopj.android.http.TextHttpResponseHandler;

import org.json.JSONObject;

import cz.msebera.android.httpclient.Header;

/* renamed from: cn.com.smartdevices.bracelet.j.a */
public class AdvHttpClient { // C1319a
    private static final int f6694a = 1;
    private static final int f6695b = 2;
    private static final String f6696c = "AdvHttpClient";

    static final class C1320b extends TextHttpResponseHandler { // C0653Y
        final /* synthetic */ String f6697a;
        final /* synthetic */ TextHttpResponseHandler f6698b;

        C1320b(String str, TextHttpResponseHandler c0653y) {
            this.f6697a = str;
            this.f6698b = c0653y;
        }

        public void onFailure(int i, Header[] headerArr, String str, Throwable th) {
            GuliLog.m12370d("AdvHttpClient", "-----onFailure---------");
            GuliLog.m12370d("AdvHttpClient", "url = " + this.f6697a);
            GuliLog.m12370d("AdvHttpClient", "res = " + str);
            GuliLog.m12370d("AdvHttpClient", "-----onFailure---------");
            this.f6698b.onFailure(i, headerArr, str, th);
        }

        public void onSuccess(int i, Header[] headerArr, String str) {
            AdvHttpClient.m11557b(str, this.f6697a);
            GuliLog.tracePrintInfo("AdvHttpClient", "-----onSuccess---------");
            GuliLog.tracePrintInfo("AdvHttpClient", "url = " + this.f6697a);
            GuliLog.tracePrintInfo("AdvHttpClient", "res = " + str);
            GuliLog.tracePrintInfo("AdvHttpClient", "-----onSuccess---------");
            this.f6698b.onSuccess(i, headerArr, str);
        }
    }

    private static void m11548a(AsyncHttpClient c2894a, int i, String str, RequestParams requestParams, TextHttpResponseHandler c0653y) {
        ResponseHandlerInterface c1320b = new C1320b(str, c0653y); // C0642S
        if (i == f6695b) {
            c2894a.get(str, requestParams, c1320b); // m21145b
        } else if (i == f6694a) {
            c2894a.post(str, requestParams, c1320b); // m21155c
        }
    }

    static final class C1321c extends AsyncHttpResponseHandler {
        final /* synthetic */ String f6699a;
        final /* synthetic */ AsyncHttpResponseHandler f6700b;

        C1321c(String str, AsyncHttpResponseHandler c0643h) {
            this.f6699a = str;
            this.f6700b = c0643h;
        }

        public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
            GuliLog.m12370d("AdvHttpClient", "-----onFailure---------");
            GuliLog.m12370d("AdvHttpClient", "url = " + this.f6699a);
            GuliLog.m12370d("AdvHttpClient", "res = " + AdvHttpClient.m11554b(bArr));
            GuliLog.m12370d("AdvHttpClient", "-----onFailure---------");
            this.f6700b.onFailure(i, headerArr, bArr, th);
        }

        public void onSuccess(int i, Header[] headerArr, byte[] bArr) {
            String str = C3657a.f18328f;
            try {
                str = AdvHttpClient.m11554b(bArr);
                AdvHttpClient.m11557b(str, this.f6699a);
            } catch (Exception e) {
                GuliLog.m12370d("AdvHttpClient", "------onSuccess--------");
                GuliLog.m12370d("AdvHttpClient", "url = " + this.f6699a);
                GuliLog.m12370d("AdvHttpClient", "res = " + str);
                GuliLog.m12370d("AdvHttpClient", "------onSuccess--------");
                GuliLog.m12370d("AdvHttpClient", e.toString());
            }
            this.f6700b.onSuccess(i, headerArr, bArr);
        }
    }

    private static void m11549a(AsyncHttpClient c2894a, int i, String str, RequestParams requestParams, AsyncHttpResponseHandler c0643h) {
        ResponseHandlerInterface c1321c = new C1321c(str, c0643h);
        if (i == f6695b) {
            c2894a.get(str, requestParams, c1321c);
        } else if (i == f6694a) {
            c2894a.post(str, requestParams, c1321c);
        }
    }

    public static void m11550a(AsyncHttpClient c2894a, String str, RequestParams requestParams, TextHttpResponseHandler c0653y) {
        AdvHttpClient.m11548a(c2894a, (int) f6695b, str, requestParams, c0653y);
    }

    public static void m11551a(AsyncHttpClient c2894a, String str, RequestParams requestParams, AsyncHttpResponseHandler c0643h) {
        AdvHttpClient.m11549a(c2894a, (int) f6695b, str, requestParams, c0643h);
    }

    private static boolean m11553a(String str) {
        return C1328k.m11582b(str);
    }

    private static String m11554b(byte[] bArr) {
        String str = C3657a.f18328f;
        if (bArr == null || bArr.length <= 0) {
            return str;
        }
        try {
            return new String(bArr);
        } catch (Exception e) {
            GuliLog.tracePrintInfo("chenee", "Utils.java getStringFromBytes error:" + e.getMessage());
            return str;
        }
    }

    public static void m11555b(AsyncHttpClient c2894a, String str, RequestParams requestParams, TextHttpResponseHandler c0653y) {
        AdvHttpClient.m11548a(c2894a, (int) f6694a, str, requestParams, c0653y);
    }

    public static void post(AsyncHttpClient c2894a, String str, RequestParams requestParams, AsyncHttpResponseHandler c0643h) { // m11556b
        AdvHttpClient.m11549a(c2894a, (int) f6694a, str, requestParams, c0643h);
    }

    private static void m11557b(String str, String str2) {
        try {
            if (!AdvHttpClient.m11553a(str2) && ((Integer) new JSONObject(str).get("code")).intValue() != 0) {
            }
        } catch (Exception e) {
            GuliLog.m12370d(f6696c, e.toString());
        }
    }
}
